
import { Component, OnInit, Injector, TemplateRef, ViewChild, Input } from '@angular/core';
import { NgZorroPageBaseComponent } from '../../core/ng-zorro-page-base-component/ng-zorro-page-base-component.component';
import { HttpService } from "../../core/service/http.service";
import { HttpClient } from "@angular/common/http";
import { Router, NavigationExtras } from "@angular/router";
import {
  AndOr, Compare, ExpressionPair, PagedResultDto, PagerSearchInput, ElementViewType, BaseComponentConfig,
  SystemFormControl, FieldType, ElementShowType, CustomNavigation, ClassInfoOutput, NavigatType, ArSystemFormControl, ClassSchool
} from "../..";
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { CityListComponent } from '../school/cityList';
import {
  FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators,
  FormControl
} from "@angular/forms";

@Component({
  selector: 'app-studenttrain',
  templateUrl: './studenttrain.component.html',
  styleUrls: ['./studenttrain.component.scss']
})
export class StudenttrainComponent implements OnInit {

  stop = true;
  isVisible = false;
  isOkLoading = false;
  dataSet;
  proList;
  roleList;
  roleid = null; // 是否点击角色演练
  trainid;
  subjectid; // 大项目ID
  teacherId;
  drillType = 0;
  selectSubject;
  ngOnInit() {
    this.http1.post<any>("StudentInfo/GetAllProjectToSubject", "").then(e => {
      this.dataSet = e.filter(q => q.count > 0);
    });
  }

  constructor(
    public http1: HttpService,
    private modalService: NzModalService,
    public http: HttpClient,
    public router: Router

  ) {

  }





  hover(j) {
    if (this.stop) {
      for (let i = 0; i < this.dataSet.length; i++) {
        this.dataSet[i].listshow = false;
        if (i !== j) {
          this.dataSet[i].shadow = true;
        }
        if (i === j) {
          this.dataSet[i].listshow = true;
        }
      }
    }
  }

  leave() {
    if (this.stop) {
      for (let i = 0; i < this.dataSet.length; i++) {
        this.dataSet[i].shadow = false;
      }
      for (let i = 0; i < this.dataSet.length; i++) {
        this.dataSet[i].listshow = false;
      }
    }
  }

  choose(j, s, id, proid, teacherId) {
    for (let i = 0; i < this.dataSet[s].subject.length; i++) {
      if (i === j) {
        if (this.dataSet[s].subject[i].isChecked) {
          this.stop = true;
          this.dataSet[s].subject[j].isChecked = false;
          this.selectSubject = null;
        } else {
          this.dataSet[s].subject[j].isChecked = true;
          this.selectSubject = this.dataSet[s].subject[j];
          this.stop = false;
        }
      } else {
        this.dataSet[s].subject[i].isChecked = false;
      }
    }
    // console.log(this.selectSubject);
    const ids = { sid: id };
    this.subjectid = id;
    this.teacherId = teacherId;
    this.http1.post<any>("StudentInfo/GetSubjectRole", ids).then(e => {
      this.roleList = e;

    });
  }

  showModal(id) {
    this.drillType = (+id) - 1;
    if (id === "3") {
      this.drillType = 2;
    }

    this.isVisible = true;
  }
  showModalroleid(num, id) {
    this.drillType = 1;
    this.roleid = id;
    this.isVisible = true;
  }

  handleOk(): void {
    this.isOkLoading = true;
    window.setTimeout(() => {
      this.isVisible = false;
      this.isOkLoading = false;
    }, 1000);
    // "teacherInfoId": 0,
    // "projectId": 0,

    const isd = { 'courseId': 0, 'creatorRoleId': this.roleid, 'drillSubjectId': this.subjectid, 'drillType': this.drillType, "id": 0, "teacherInfoId": this.teacherId };
    this.http1.post<any>("DrillRecord/SaveDrillRecord", isd).then(e => {
      this.roleList = e;
      if (this.drillType === 2) {
        this.router.navigate(['app/mydrill/hall/index']);
      } else if (this.drillType === 1) { // 视频类型
        this.router.navigate(['app/mydrill/hall/index']);
      } else {
        this.router.navigate(['app/mytrainindex']);
      }

    });
  }

  handleCancel(): void {
    this.isVisible = false;
  }

  getIndex(index: number) {
    index += 1;
    let reslut = index > 4 ? index % 4 : index;
    reslut = reslut === 0 ? reslut + 1 : reslut;
    return reslut;
  }
}
